package org.alerve.android.resourcebuilder.modules;

import org.alerve.android.resourcebuilder.IModule;
import org.alerve.android.resourcebuilder.Layout;
import org.alerve.android.resourcebuilder.AbstractDirector.ModuleClass;

import android.app.Dialog;
import android.view.InflateException;
import android.view.View;

/**
 * Concrete implementation of {@link IModule} for {@link Dialog} instances
 * 
 * @author pabs87@gmail.com
 * 
 */
@ModuleClass(Dialog.class)
public class DialogModule extends DecoratorModule<Dialog> {

	public DialogModule() {
		super();
		addModule(new DialogInflator());
		addModule(new DialogPopulator());
	}

	private final class DialogInflator extends InflatorModule<Dialog> {

		@Override
		protected boolean inflate(Dialog subject, Layout layout) {
			if (layout == null) {
				throw new InflateException("Dialog must have a layout");
			}
			subject.setContentView(layout.value());
			return true;
		}

	}

	private final class DialogPopulator extends PopulatorModule<Dialog> {

		@Override
		protected View findViewById(Dialog parent, int id) {
			return parent.findViewById(id);
		}

	}

}
